home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / rkeyboar.cpt / Reactive Keyboard ƒ / Printing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-29  |  2.2 KB  |  90 lines

  1. #include <MacIncludes.h>
  2.  
  3. #define MARGINS     20
  4.  
  5.  
  6. THPrint        gPrinterRecord;
  7. TPPrPort    gPrinterPort;
  8.  
  9.  
  10. void PrintText(TEHandle hTE)
  11. {
  12.  
  13.     int         totalLines;
  14.     Rect        rView;
  15.     GrafPtr        oldPort;
  16.     Rect        oldView;
  17.     Rect        oldDest;
  18.     int            totalHeight;
  19.     int            currentLine;
  20.     int            scrollAmount;
  21.     Rect        zeroRect={ 0,0,0,0 };
  22.     TPrStatus    thePrinterStatus;
  23.     Boolean        OpenPrintManager;
  24.     Boolean        abort;
  25.     int            viewHeight;
  26.  
  27.     
  28.     OpenPrintManager = false;
  29.     if (gPrinterRecord){
  30.         PrOpen();
  31.         if (PrJobDialog( gPrinterRecord )){
  32.             GetPort( &oldPort );
  33.             oldView = (*hTE)->viewRect; 
  34.             oldDest = (*hTE)->destRect;
  35.             gPrinterPort = PrOpenDoc( gPrinterRecord, nil, nil );
  36.             OpenPrintManager = ( PrError() == noErr );
  37.         }
  38.     }
  39.  
  40.     if (OpenPrintManager){
  41.         SetPort( (GrafPtr) gPrinterPort); 
  42.         rView = (*gPrinterRecord)->prInfo.rPage; 
  43.         InsetRect( &rView, MARGINS, MARGINS );  
  44.         (*hTE)->inPort = (GrafPtr)gPrinterPort; 
  45.         (*hTE)->destRect = rView;
  46.         (*hTE)->viewRect = rView; 
  47.         TECalText(hTE); 
  48.         totalLines = (*hTE)->nLines; 
  49.         totalHeight = TEGetHeight(totalLines, 0, hTE);
  50.         (*hTE)->destRect.bottom = (*hTE)->destRect.top + totalHeight; 
  51.         
  52.         abort = false;
  53.         currentLine = 1; 
  54.         
  55.         while(!abort&& (currentLine <= totalLines)){
  56.             PrOpenPage( gPrinterPort, nil );
  57.             scrollAmount = 0;
  58.             ClipRect( &(*gPrinterRecord)->prInfo.rPage ); 
  59.             viewHeight = (*hTE)->viewRect.bottom - (*hTE)->viewRect.top + 1;
  60.             while ((( scrollAmount + TEGetHeight( currentLine, currentLine, hTE ) ) <= viewHeight )
  61.                 && ( currentLine <= totalLines ) ){
  62.                 scrollAmount = scrollAmount + TEGetHeight( currentLine, currentLine, hTE );
  63.                 currentLine = currentLine + 1;
  64.             } 
  65.             
  66.             (*hTE)->viewRect.bottom = scrollAmount + MARGINS; 
  67.             TEDeactivate( hTE ); 
  68.             TEUpdate( &(*hTE)->viewRect, hTE ); 
  69.             ClipRect( &zeroRect ); 
  70.             TEScroll( 0, -scrollAmount, hTE ); 
  71.             (*hTE)->viewRect.bottom = rView.bottom; 
  72.             if (PrError() == iPrAbort){
  73.                 abort = true;
  74.             }
  75.             PrClosePage( gPrinterPort ); 
  76.         }
  77.  
  78.         PrCloseDoc( gPrinterPort );
  79.         if (((*gPrinterRecord)->prJob.bJDocLoop == bSpoolLoop ) && ( PrError == noErr )){
  80.             PrPicFile( gPrinterRecord, nil, nil, nil, &thePrinterStatus );
  81.         }
  82.         PrClose();
  83.         SetPort( oldPort );
  84.         (*hTE)->inPort = oldPort;
  85.         (*hTE)->viewRect = oldView;
  86.         (*hTE)->destRect = oldDest;
  87.         TEUpdate( &oldView, hTE );
  88.     }
  89. }
  90.